#ifndef __SUPER_H__ 
#define __SUPER_H__

#include <stdint.h>
#include "rb_tree.h"
#include "kernel.h"

struct wffs_block_group_cache_entry
    {
    uint32_t phy_bg_num;

    uint32_t erase_cnt;

    uint32_t dirty;
    uint32_t obsolete;
    };

struct wffs_free_space_cache_node
    {
    uint64_t start;
    uint64_t end;
    RB_ENTRY(wffs_free_space_cache_node) rb_node;
    };

struct wffs_tree_root
    {
    void *root_block;
    uint64_t version;
    uint64_t block_nr;
    };

struct wffs_sb_info
    {
    struct flash_descriptor *mtd;
    struct super_block *vfs_sb;

    /*index tree root*/
    struct wffs_tree_root *index_tree_root;

    /*extent tree root*/
    struct wffs_tree_root extent_tree_root;

    /*
     * block group cache which contains: 
     * 1,map between physical group #and logical group# 
     * 2,block group description 
     */
    struct wffs_block_group_cache_entry *bg_cache_table;

    /*free space cache*/
	
	RB_HEAD(wffs_free_space_cache, wffs_free_space_cache_node)free_space_cache;

    /*syner inode which map the whole flash*/
    struct inode syner_inode;
    };

struct wffs_static_raw_super_block
	{
	uint64_t magic;
	/*hardware info*/
	uint64_t flash_size;
	uint32_t flash_pg_size;
	uint32_t flash_eb_size;
	/*software info*/
    uint32_t flash_block_size;
	uint32_t flash_bg_size;
	/*others*/
	uint64_t bg_map_offset;
	uint32_t sb_link_level;
	} __attribute__ ((__packed__));

struct wffs_float_raw_super_block
    {
    uint64_t magic;
    uint64_t version;

    uint64_t used_blocks;
    uint64_t index_tree_root;
    uint64_t extent_tree_root;
    } __attribute__ ((__packed__));

struct wffs_raw_sb_head
    {
    uint64_t magic;
    uint64_t link;
    uint64_t version;
    } __attribute__ ((__packed__));

struct wffs_raw_sb_link
    {
    uint64_t magic;
    uint64_t link;
    uint64_t version;
    } __attribute__ ((__packed__));

int init_wffs(void);
#endif /* __SUPER_H__ */

